﻿@model List<Mysoft.ModelAnalysis.Models.MetadataEntity>
@{
    Layout = null;
    ViewBag.Title = "分库相关检查";
    List<Mysoft.ModelAnalysis.Models.MetadataEntity> entitys = Model as List<Mysoft.ModelAnalysis.Models.MetadataEntity>;
}
<style>
    .spantitle {
        font-size: 24px;
        font-weight: bold;
        cursor: pointer;
        padding-left: 10px;
    }
</style>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
@*<button onclick="addBuguid(this)">给分库的表添加公司GUID</button>*@
<div>
    <span class="spantitle">不分库的表</span><span style="cursor:pointer;" onclick="modelDisplay(this)">折叠/展开</span>
    <div style="display:none">
        @foreach (var entity in entitys.Where(t => t.IsEnableIsolateForCompany == false))
        {
            <div>@entity.Name</div>

            @*var str= "<table name=\""+@entity.Name+"\">" +
                       "select count(1) from " + @entity.Name
                    + "</table>";

                <div>@str</div>*@
        }
    </div>
</div>

<div>
    <label class="spantitle">分库的表</label><span style="cursor:pointer;" onclick="modelDisplay(this)">折叠/展开</span>
    <div style="display:none">
        @foreach (var entity in entitys.Where(t => t.IsEnableIsolateForCompany == true))
        {
            <div>@entity.Name</div>

            @*var str = "select count(1) from " + @entity.Name;

                <div>@str</div>*@
        }
    </div>
</div>

<div>
    <label class="spantitle">分库的表,但是没有公司id</label><span style="cursor:pointer;" onclick="modelDisplay(this)">折叠/展开</span>
    @{
        var errorEntity = entitys.Where(t => t.IsEnableIsolateForCompany == true
        && (t.Attributes.MetadataAttributes.Any(m => string.Equals(m.Name, "buguid", StringComparison.OrdinalIgnoreCase)) == false)
        );
    }
    <div style="display:none">
        @foreach (var entity in errorEntity)
        {
            <div>@entity.Name</div>
        }
    </div>
</div>
<div>
    <label class="spantitle">sql检查</label><span style="cursor:pointer;" onclick="modelDisplay(this)">折叠/展开</span>
    <div>
        <div>分库连接字符 <input style="width:100%" id="txtFkSqlConn" value="server=10.5.11.218\sql2012;database=dotnet_erpV20_SL_HN;uid=sa;pwd=95938;" /></div>
        <div>主库连接字符 <input style="width:100%" id="txtZkSqlConn" value="server=10.5.10.114\sql2012;database=dotnet_erpV20_SL;uid=sa;pwd=95938;" /></div>
        <div>分库公司id <input style="width:100%" id="txtFkGuid" value="a86529f6-12de-42c3-fddc-08d80e948b6d" /></div>
        <div><button onclick="jiaoyan(this)">计算</button></div>
        <div>只要分库表没有数据（在分库上查询），显示数据为0的数据 <textarea id="FkbNoData"></textarea></div>
        <div>只要分库的表（在主库上查询），显示数据 > 0的数据 <textarea id="FkbZkNoData"></textarea></div>
        <div>不分库的表，在两个库上都有数据，数据要相等 <textarea id="BfkbNoEqual"></textarea></div>
        <div>未计算的表 <textarea id="NoCal"></textarea></div>
    </div>
</div>

<script>
    function modelDisplay(obj) {
        var $this = $(obj);
        $this.nextAll("div").toggle();
    }

    function addBuguid(obj) {
        var $obj = $(obj);
        $obj.attr("disabled", "disabled");
        $.ajax({
            url: "@Url.Action("AddBuguid")",
            success: function () {
                alert("添加成功");
            },
            error: function (a, b, c) {
                debugger
                alert("添加失败");
            },
            complete: function () {
                $obj.removeAttr("disabled");
            }
        });
    }

    function jiaoyan(obj) {
        var $obj = $(obj);
        $obj.attr("disabled", "disabled");
        $.ajax({
            url: "@Url.Action("CaleCount")",
            dataType: "json",
            data: "fkSqlConn=" + $("#txtFkSqlConn").val().trim() + " &zkSqlConn=" + $("#txtZkSqlConn").val().trim() + "&fkBuGuid=" + $("#txtFkGuid").val().trim(),
            success: function (a) {
                var FkbNoData = "";
                for (var i = 0; i < a.FkbNoData.length; i++) {
                    FkbNoData += a.FkbNoData[i].TableName+"、";
                }
                $("#FkbNoData").val(FkbNoData);

                var FkbZkNoData = "";
                for (var i = 0; i < a.FkbZkNoData.length; i++) {
                    FkbZkNoData += a.FkbZkNoData[i].TableName + "、";
                }
                $("#FkbZkNoData").val(FkbZkNoData);

                var BfkbNoEqual = "";
                for (var i = 0; i < a.BfkbNoEqual.length; i++) {
                    BfkbNoEqual += a.BfkbNoEqual[i].TableName + "、";
                }
                $("#BfkbNoEqual").val(BfkbNoEqual);

                var NoCal = "";
                for (var i = 0; i < a.NoCal.length; i++) {
                    NoCal += a.NoCal[i].TableName + "、";
                }
                $("#NoCal").val(NoCal);
            },
            error: function (a, b, c) {
                debugger
            },
            complete: function () {
                $obj.removeAttr("disabled");
            }
        });
    }

</script>
